package display;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class OptionFrame extends JFrame {

    public static JTextField jTextField1=new JFormattedTextField();
    public static JTextField jTextField2=new JFormattedTextField();
    public static JTextField jTextField3=new JFormattedTextField();
    private SetFocusListener setFocusListener=new SetFocusListener();

    OptionFrame() {
        this.setTitle("难度设置");
        this.setSize(550, 500);
        this.setLocationRelativeTo(null);
        JPanel panel = new JPanel();
        panel.setBackground(new Color(201,226,252));
        panel.setLayout(null);

        JRadioButton button1=new JRadioButton("初级：  9*  9  雷数：10");
        JRadioButton button2=new JRadioButton("中级：16*16  雷数：40");
        JRadioButton button3=new JRadioButton("高级：30*16  雷数：99");
        JRadioButton button4=new JRadioButton("自定义：");
        button1.setOpaque(false);
        button2.setOpaque(false);
        button3.setOpaque(false);
        button4.setOpaque(false);
        JButton button5=new JButton("确定");
        JButton button6=new JButton("取消");

        ButtonGroup buttonGroup=new ButtonGroup();

        JLabel label1=new JLabel("长度(9~36)：");
        JLabel label2=new JLabel("宽度(9~22)：");
        JLabel label3=new JLabel("雷数(10+)  ：");


        button1.addActionListener(new SetDataListener(9,9,10));
        button2.addActionListener(new SetDataListener(16,16,40));
        button3.addActionListener(new SetDataListener(30,16,99));
        button1.addFocusListener(setFocusListener);
        button2.addFocusListener(setFocusListener);
        button3.addFocusListener(setFocusListener);
        button4.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                jTextField1.setEnabled(true);
                jTextField2.setEnabled(true);
                jTextField3.setEnabled(true);
            }
        });
        button5.addActionListener(new SetListener());
        button6.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                OptionFrame.this.setVisible(false);
            }
        });

        Font font = new Font("微软雅黑", Font.PLAIN, 20);
        button1.setFont(font);
        button2.setFont(font);
        button3.setFont(font);
        button4.setFont(font);
        button5.setFont(font);
        button6.setFont(font);
        label1.setFont(font);
        label2.setFont(font);
        label3.setFont(font);
        jTextField1.setFont(font);
        jTextField2.setFont(font);
        jTextField3.setFont(font);
        button1.setBounds(30,20,300,50);
        button2.setBounds(30,70,300,50);
        button3.setBounds(30,120,300,50);
        button4.setBounds(30,170,300,50);
        button5.setBounds(120,390,100,40);
        button6.setBounds(300,390,100,40);
        label1.setBounds(60,220,200,50);
        label2.setBounds(60,270,200,50);
        label3.setBounds(60,320,200,50);
        jTextField1.setBounds(185,230,60,30);
        jTextField2.setBounds(185,280,60,30);
        jTextField3.setBounds(185,330,60,30);

        buttonGroup.add(button1);
        buttonGroup.add(button2);
        buttonGroup.add(button3);
        buttonGroup.add(button4);

        panel.add(button1);
        panel.add(button2);
        panel.add(button3);
        panel.add(button4);
        panel.add(button5);
        panel.add(button6);
        panel.add(label1);
        panel.add(label2);
        panel.add(label3);
        panel.add(jTextField1);
        panel.add(jTextField2);
        panel.add(jTextField3);
        this.add(panel);
    }
}
